package com.example.hao.eventdistribution;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        findViewById(R.id.mtv).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Toast.makeText(MainActivity.this, "被你找到了", Toast.LENGTH_SHORT).show();
//            }
//        });

//        findViewById(R.id.mtv).setOnTouchListener(new View.OnTouchListener() {
//            @Override
//            public boolean onTouch(View v, MotionEvent event) {
//
//                Log.d(TAG, "onTouch: "+v.getTag());
//
//                return false;
//            }
//        });

    }

    /**
     * 事件分发
     *
     * @param ev
     * @return true / false:表示终止整条事件链的传递;
     */
    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        Log.d(TAG, "dispatchTouchEvent: ");
////        return true;
////        return false;
        return super.dispatchTouchEvent(ev);
    }

    /**
     * 事件消费
     *
     * @param event
     * @return
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
        Log.d(TAG, "onTouchEvent: ");
//        return super.onTouchEvent(event);
        return true;
    }


    public void testChild4(View view) {
        Toast.makeText(this, "找到我了哦", Toast.LENGTH_SHORT).show();
    }


}
